{*******************************************************}
{                                                       }
{       DevOnRails                                      }
{                                                       }
{       Copyright (C) 2012 AllanGomes                   }
{                                                       }
{*******************************************************}

unit Rails.Vcl.Field;

interface

uses
  RTTI, Rails.Vcl.Interfaces, Vcl.ExtCtrls, Vcl.StdCtrls, Vcl.Controls,
  System.Types, Rails.ActiveRecord.Attributes,
  Aurelius.Mapping.Explorer, Vcl.ComCtrls, Rails.Vcl.Components, Rails.Metadata;

type
{$REGION 'TField'}
  TField = class(TInterfacedObject, IField)
  private
    Pnl: TPanel;
    Lbl: TLabel;
    Edt: TRailsEdit;
    Cmb: TRailsComboBox;
    Rdt: TRailsDate;
    Rtm: TRailsTime;
    Rdtt: TRailsDateTime;
    chk: TCheckBox;
  public
    constructor Create(Const AColumn: TRailsColumn; const Parent: TWinControl; const AOwner: IControls; var Position: TPoint);
  end;
{$ENDREGION}

implementation

uses
  TypInfo, Vcl.Forms, Cliente.Model, System.Generics.Collections, SysUtils, DB,
  Rails.Vcl.Controls, Rails.Vcl.Factory, Dialogs;

procedure CreateControl(var Control:IControls);
begin
  Control := TControls<TObject>.Create(nil);
end;

{$REGION 'TField'}
{ TField }

constructor TField.Create(Const AColumn: TRailsColumn; const Parent: TWinControl; const AOwner: IControls; var Position: TPoint);
var
  AutoCreate: Boolean;
  ConstructorField: IConstructorFields;
begin
  AOwner.BeforeFieldCreate(AColumn, Parent, Position, AutoCreate);
  {$MESSAGE Warn 'Implementar todos os casos da propiedade'}
  if AutoCreate then
  begin
    Pnl := TPanel.Create(Parent);
    Pnl.Parent := Parent;
    Pnl.BevelOuter := bvLowered;
    Pnl.Left := Position.X+8;
    Pnl.Top := Position.Y;
    Pnl.Height := 35;
    Pnl.Name := 'pnl'+AColumn.ColumnName;
    Pnl.Caption := '';
    Pnl.Width := AColumn.Precision*8;
    ConstructorField := TConstructorFields.Create(AColumn, Pnl);
    ConstructorField.Title(Lbl);
    ConstructorField.setLabelTitle(Lbl);
    case AColumn.ColumnType of
      ctString: ConstructorField.Edit(Edt);
      ctFloat: ConstructorField.Edit(Edt);
      ctEnumerator: ConstructorField.ComboBox(Cmb);
      ctInteger: ConstructorField.Edit(Edt);
      ctDate: ConstructorField.RailsDate(Rdt);
      ctTime: ConstructorField.RailsTime(Rtm);
      ctDateTime: ConstructorField.RailsDateTime(Rdtt);
      ctBoolean: ConstructorField.CheckBox(chk);
      {$MESSAGE Warn 'Implementar Memo'}
      {$MESSAGE Warn 'Implementar Blob'}
    end;
    Pnl.BevelOuter := bvNone;
    Position.Y := Position.Y+Pnl.Height;
  //  Position.X := Position.X+Pnl.Width;
    AOwner.AfterFieldCreate(AColumn, Pnl);
    AOwner.AfterFieldCreate(AColumn, [Pnl, Lbl, Edt]);
  end;
end;
{$ENDREGION}

end.




